//
//  ZZNavigationControllerStack.m
//  zhengzai-tv
//
//  Created by SC on 16/7/5.
//  Copyright © 2016年 zhengzai.tv. All rights reserved.
//

#import "ZZNavigationControllerStack.h"

@interface ZZNavigationControllerStack ()

@property (nonatomic, strong) NSMutableArray *navigationControllers;

@end

@implementation ZZNavigationControllerStack

DEF_SINGLETON

- (NSMutableArray *)navigationControllers
{
    if (_navigationControllers == nil) {
        _navigationControllers = [NSMutableArray array];
    }
    return _navigationControllers;
}

+ (void)pushNavigationController:(UINavigationController *)navigationController
{
    [[ZZNavigationControllerStack sharedInstance] pushNavigationController:navigationController];
}

+ (UINavigationController *)popNavigationController
{
    return [[ZZNavigationControllerStack sharedInstance] popNavigationController];
}

+ (UINavigationController *)topNavigationController
{
    return [[ZZNavigationControllerStack sharedInstance] topNavigationController];
}

+ (void)clear
{
    [[ZZNavigationControllerStack sharedInstance] clear];
}

- (void)pushNavigationController:(UINavigationController *)navigationController {
    if ([self.navigationControllers containsObject:navigationController]) return;
    [self.navigationControllers addObject:navigationController];
}

- (UINavigationController *)popNavigationController {
    UINavigationController *navigationController = self.navigationControllers.lastObject;
    [self.navigationControllers removeLastObject];
    return navigationController;
}

- (UINavigationController *)topNavigationController {
    return self.navigationControllers.lastObject;
}

- (void)clear
{
    [self.navigationControllers removeAllObjects];
}

@end
